Skip to content

feat(BA-6659): materialize the Project scope's virtual scope on creation#12931

Draft
fregataa wants to merge 4 commits into
mainfrom
feat/BA-6659-apply-virtual-scope-project
Draft

feat(BA-6659): materialize the Project scope's virtual scope on creation#12931
fregataa wants to merge 4 commits into
mainfrom
feat/BA-6659-apply-virtual-scope-project

Conversation

@fregataa

@fregataa fregataa commented Jul 16, 2026

Copy link
Copy Markdown
Member

Summary

  • GroupDBSource.create now materializes the project's virtual scope node (with its self-membership) in the same transaction as the project row and its RBAC roles, so a project becomes capable of owning child entities through the virtual-scope chain.
  • Add RBACWriteOps.create_virtual_scope, a public entry point that creates the virtual scope node for a scope entity whose row is created through a separate path (here, RBACEntityCreator, which keeps the existing domain→project ownership association).

Resolves BA-6659

🤖 Generated with Claude Code

@github-actions github-actions Bot added size:S 10~30 LoC comp:manager Related to Manager component labels Jul 16, 2026
fregataa added a commit that referenced this pull request Jul 17, 2026
@fregataa
fregataa force-pushed the feat/BA-6659-apply-virtual-scope-project branch from dc66545 to 0aa0b48 Compare July 21, 2026 04:41
@fregataa
fregataa marked this pull request as ready for review July 21, 2026 04:58
@fregataa
fregataa requested a review from a team as a code owner July 21, 2026 04:58
Copilot AI review requested due to automatic review settings July 21, 2026 04:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Comment on lines +186 to +195
await self._role_manager.create_preset_roles(db_session, data.scope_id())

return data
async with self._rbac_ops_provider.write_ops() as w:
await w.ensure_scope(
ScopeRef(
scope_type=VScopeType(RBACElementType.PROJECT.value),
scope_id=data.id,
)
)
return data

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll adjust the timing for that part using ops as well.

@fregataa
fregataa force-pushed the feat/BA-6659-apply-virtual-scope-project branch from 0aa0b48 to fa84f07 Compare July 21, 2026 06:44
@github-actions github-actions Bot added size:XL 500~ LoC and removed size:S 10~30 LoC labels Jul 21, 2026
@fregataa
fregataa requested a review from a team July 21, 2026 06:49
@fregataa
fregataa marked this pull request as draft July 21, 2026 07:26
@fregataa
fregataa force-pushed the feat/BA-6659-apply-virtual-scope-project branch from fa84f07 to bd73e00 Compare July 22, 2026 06:22
fregataa and others added 4 commits July 23, 2026 11:50
Create a project's virtual scope through the ensure_scope RBAC op after the
project row is created, so the project owns its child entities through the
virtual-scope chain. The virtual-scope write runs in its own transaction via
the injected RBAC ops provider.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Creating a scope now goes through one ops call that writes the row with its
parent association, its virtual scope, its SYSTEM roles, and the roles its
scope type's presets call for — so project creation is a single transaction
again instead of splitting the virtual-scope write off on its own.

- ScopeCreation becomes an ABC: an implementation names the row to insert and
  derives the scope from it, so the id stays database-generated.
- Role provisioning is bulk: one insert for every role and one for every
  permission, whatever the number of scopes.
- Scopes are addressed by ScopeRef throughout; the role/permission enums are
  reached only where the rows are written.
- GroupCreatorSpec declares its integrity_error_checks, replacing the three
  pre-check SELECTs in GroupDBSource.create with the constraints themselves,
  which also closes the check-then-insert race.

The system-role test now asserts the roles and permissions the database ends
up with rather than the calls made to RoleManager.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…h RBAC ops

Project purge and user add/remove now go through the RBAC ops provider so
every membership change is recorded on the virtual-scope chain and scope
deletion owns its whole contract.

- remove_entity_members takes an EntityMembersRemoval mirroring the
  addition: members whose assign_role_on names a user also get every role
  at the scope revoked.
- delete_scope/batch_delete_scopes accept RBAC entity purgers, so a scope
  delete cleans its permissions and scope associations along with the row
  and its virtual scope node.
- GroupDBSource modify/assign/unassign/bind/unbind use add_entity_members
  and remove_entity_members via write_ops; purge_group deletes the group
  through delete_scope with the new ProjectPurgerSpec.
- The db_source addresses projects and users by ProjectID/UserID, with the
  repository converting at its boundary.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…nel purge guard

- remove_entity_members takes a scope and entity refs directly; membership
  removal no longer revokes the user's roles at the scope
- replace the hand-written active-kernel pre-check in purge_group with a
  declarative conflict check on GroupKernelBatchPurgerSpec
- drop the _project_scope/_user_entity_ref wrappers and construct
  ScopeRef/EntityRef at the call sites, typed with ProjectID/UserID
- provision the virtual scope in the assign/unassign test fixtures now that
  membership writes resolve it

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@fregataa
fregataa force-pushed the feat/BA-6659-apply-virtual-scope-project branch from bd73e00 to 02b1b5c Compare July 23, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:manager Related to Manager component size:XL 500~ LoC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants